<?php echo $this->fetch('header.html'); ?>
<script type="text/javascript">
$(function(){
    $('#article_form').validate({
        errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
        },
        success       : function(label){
            label.addClass('right').text('OK!');
        },
        rules : {    
            ad_name : {
                required : true
            }
        },
        messages : {
            ad_name : {
                required : '广告标题不能为空'
            }
        }
    });
	//日期
	var myDate = new Date();
    var now_mini_time = myDate.getHours()+':'+myDate.getMinutes()+':'+myDate.getSeconds();
    $('#start_time').datepicker({dateFormat: 'yy-mm-dd '+now_mini_time});
    $('#end_time').datepicker({dateFormat: 'yy-mm-dd '+now_mini_time});
	
	//change选择
	<?php if ($this->_var['article']['ad_type']): ?>
	where_isshow(<?php echo $this->_var['article']['ad_type']; ?>);
	<?php else: ?>
	where_isshow(1);
	<?php endif; ?>
    $('#ad_type').change(function(){
		var reason_text= this.options[this.selectedIndex].value;
		where_isshow(reason_text);
    });		
});
function where_isshow(reason_text)
{
	if ( reason_text == '1') 
	{ 
	   $('#ad_type1').show();
	   $('#ad_type2').hide();
	   $('#ad_type3').hide();
	}
	if ( reason_text == '2') 
	{ 
	   $('#ad_type1').hide();
	   $('#ad_type2').show();
	   $('#ad_type3').hide();
	}
	if ( reason_text == '3') 
	{ 
	   $('#ad_type1').hide();
	   $('#ad_type2').hide();
	   $('#ad_type3').show();
	}
	return false;
}
</script>
<div id="rightTop">
    <p>广告管理</p>
    <ul class="subnav">
        <li><a class="btn1" href="index.php?app=adver">管理</a></li>
        <?php if ($this->_var['article']['id']): ?>
        <li><a class="btn1" href="index.php?app=adver&amp;act=add">新增</a></li>
        <?php else: ?>
        <li><span>新增</span></li>
        <?php endif; ?>
    </ul>
</div>
<style type="text/css">
.infoTable th {text-align: left; padding-left: 20px; width: 80px;}
</style>
<div class="info">
    <form method="post" enctype="multipart/form-data" id="article_form">
        <table class="infoTable">
            <tr>
                <th class="paddingT15">
                    广告名称:</th>
                <td class="paddingT15 wordSpacing5">
                    <input class="infoTableInput" id="ad_name" type="text" name="ad_name" value="<?php echo htmlspecialchars($this->_var['article']['ad_name']); ?>" />
                </td>
            </tr>
            <tr>
              <th class="paddingT15">媒介类型:</th>
              <td class="paddingT15 wordSpacing5">
              <select name="ad_type" id="ad_type">
                <option value="1" <?php if ($this->_var['article']['ad_type'] == '1' || ! $this->_var['article']['ad_type']): ?>selected<?php endif; ?>>代码模式</option>
                <option value="2" <?php if ($this->_var['article']['ad_type'] == '2'): ?>selected<?php endif; ?>>模板模式</option>
                <option value="3" <?php if ($this->_var['article']['ad_type'] == '3'): ?>selected<?php endif; ?>>图片模式</option>
              </select></td>
            </tr>
            <tr>
              <th class="paddingT15">开始日期:</th>
              <td class="paddingT15 wordSpacing5"><input class="infoTableInput" id="start_time" type="text" name="start_time" value="<?php echo local_date("Y-m-d H:i:s",$this->_var['article']['start_time']); ?>"/></td>
            </tr>
            <tr>
              <th class="paddingT15">结束日期:</th>
              <td class="paddingT15 wordSpacing5"><input class="infoTableInput" id="end_time" type="text" name="end_time" value="<?php echo local_date("Y-m-d H:i:s",$this->_var['article']['end_time']); ?>"/></td>
            </tr>
            <tr id="ad_type1">
              <th class="paddingT15">广告代码:</th>
              <td class="paddingT15 wordSpacing5">
				<script type="text/javascript" charset="utf-8" src="/data/ueditor/ueditor.config.js"></script>
				<script type="text/javascript" charset="utf-8" src="/data/ueditor/ueditor.all.min.js"> </script>
				<script type="text/javascript" charset="utf-8" src="/data/ueditor/lang/zh-cn/zh-cn.js"></script>
                <textarea name="ad_code" id="ad_code" style="width:98%;height:500px;"><?php echo htmlspecialchars($this->_var['article']['ad_code']); ?></textarea>
                <script type="text/javascript">var ue = UE.getEditor('ad_code');</script>
            </td>
            </tr>
            <tr id="ad_type2">
              <th class="paddingT15">模板路径:</th>
              <td class="paddingT15 wordSpacing5"><input class="infoTableInput" id="template_url" type="text" name="template_url" value="<?php echo htmlspecialchars($this->_var['article']['template_url']); ?>"/>
                *不熟悉内部结构请不要使用此模式<br />
              <?php if ($this->_var['template_code']): ?><input type="hidden" name="template_url_now" value="<?php echo htmlspecialchars($this->_var['article']['template_url']); ?>"/><textarea name="template_code" style="width:98%;height:500px;"><?php echo $this->_var['template_code']; ?></textarea><?php endif; ?></td>
            </tr>
            <tr id="ad_type3">
              <th class="paddingT15">广告图片:</th>
              <td class="paddingT15 wordSpacing5">
<table id="table1" border="0">

<?php $_from = $this->_var['article']['ad_link']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('key', 'adlink');if (count($_from)):
    foreach ($_from AS $this->_var['key'] => $this->_var['adlink']):
?>          
  <tr>
    <td><?php if ($this->_var['article']['ad_img'][$this->_var['key']]): ?><a href="<?php echo $this->_var['article']['ad_img'][$this->_var['key']]; ?>" target="_blank"><img src="<?php echo $this->_var['article']['ad_img'][$this->_var['key']]; ?>" width="120" /></a><?php endif; ?></td>
    <td valign="bottom">
    本地图片:<input name="img_local[]" type="file" style="width:180px"/>
    链接名称:<input type="text" name="ad_img_name[]" class="infoTableFile" value="<?php echo $this->_var['article']['ad_img_name'][$this->_var['key']]; ?>"/>
    <br />
    远程图片:<input type="text" name="ad_img[]" class="infoTableFile" value="<?php echo $this->_var['article']['ad_img'][$this->_var['key']]; ?>"/>
    链接:<input type="text" class="infoTableFile" name="ad_link[]" value="<?php echo $this->_var['adlink']; ?>"/>
    </td>
    <td valign="bottom">
<a href="index.php?app=adver&act=edit_drop&id=<?php echo $this->_var['article']['id']; ?>&inid=<?php echo $this->_var['key']; ?>">删除</a> <a href="javascript:void(0)" onClick="moveUp(this)">上移</a> <a href="javascript:void(0)" onClick="moveDown(this)">下移</a>
  </td>
   </tr>
<?php endforeach; else: ?>
  <tr>
     <td></td>
     <td>
      本地图片:<input name="img_local[]" type="file" style="width:180px"/>
      <br />
      远程图片:<input type="text" name="ad_img[]" class="infoTableFile"/>
      链接:<input type="text" class="infoTableFile" name="ad_link[]"/>
     </td>
     <td><a href="javascript:void(0)" onClick="moveUp(this)">上移</a> <a href="javascript:void(0)" onClick="moveDown(this)">下移</a></td>
  </tr>
<?php endif; unset($_from); ?><?php $this->pop_vars();; ?>
</table>
<a href="javascript:;" id="add_adver">新增广告图片</a>
<script type="text/javascript">
$(function(){
	var i = 1;
    $("#add_adver").click(function(){
	  //$("#ad_adone:last").after($("#ad_adone:last").clone().val(0));
	  //复制一行
		var tr = $("#table1 tr").eq(0).clone();
		tr.show();
		tr.appendTo("#table1");	  
    });
});
<!--
function cleanWhitespace(element) {
    //遍历element的子结点
    for (var i = 0; i < element.childNodes.length; i++) {
     var node = element.childNodes[i];
     //判断是否是空白文本结点，如果是，则删除该结点
     if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
     node.parentNode.removeChild(node);
    }
}
//获得表格对象
var _table=document.getElementById("ad_adone");
cleanWhitespace(_table);
//使表格行上移，接收参数为链接对象
function moveUp(_a){
    //通过链接对象获取表格行的引用
    var _row=_a.parentNode.parentNode;
    //如果不是第一行，则与上一行交换顺序
    if(_row.previousSibling)swapNode(_row,_row.previousSibling);
}
//使表格行下移，接收参数为链接对象
function moveDown(_a){
    //通过链接对象获取表格行的引用
    var _row=_a.parentNode.parentNode;
    //如果不是最后一行，则与下一行交换顺序
    if(_row.nextSibling)swapNode(_row,_row.nextSibling);
}
//定义通用的函数交换两个结点的位置
function swapNode(node1,node2){
    //获取父结点
    var _parent=node1.parentNode;
    //获取两个结点的相对位置
    var _t1=node1.nextSibling;
    var _t2=node2.nextSibling;
    //将node2插入到原来node1的位置
    if(_t1)_parent.insertBefore(node2,_t1);
    else _parent.appendChild(node2);
    //将node1插入到原来node2的位置
    if(_t2)_parent.insertBefore(node1,_t2);
    else _parent.appendChild(node1);
}
//-->
</script>              
              </td>
          </tr>            
          <tr>
              <th class="paddingT15">广告联系人:</th>
    <td class="paddingT15 wordSpacing5"><input class="infoTableInput" id="link_name" type="text" name="link_name" value="<?php echo htmlspecialchars($this->_var['article']['link_name']); ?>"/></td>
            </tr>
            <tr>
              <th class="paddingT15">联系方式:</th>
              <td class="paddingT15 wordSpacing5"><input class="infoTableInput" id="link_contact" type="text" name="link_contact" value="<?php echo htmlspecialchars($this->_var['article']['link_contact']); ?>"/></td>
            </tr>
            <tr>
              <th class="paddingT15">添加时间:</th>
              <td class="paddingT15 wordSpacing5"><?php echo local_date("Y-m-d H:i:s",$this->_var['article']['add_time']); ?></td>
            </tr>
            <tr>
                <th class="paddingT15">
                    <label for="article">是否开启:</label></th>
                <td class="paddingT15 wordSpacing5"><label><input name="enabled" type="radio" id="enabled" value="1" <?php if ($this->_var['article']['enabled'] == '1' || ! $this->_var['article']['enabled']): ?>checked<?php endif; ?>/>开启</label>
                <label><input type="radio" name="enabled" id="enabled" value="0" <?php if ($this->_var['article']['enabled'] == '0'): ?>checked<?php endif; ?>/>关闭</label></td>
            </tr>
        <tr>
            <th></th>
            <td class="ptb20">
              <input class="formbtn" type="submit" name="Submit" value="提交" />
                <input class="formbtn" type="reset" name="Submit2" value="重置" />
            </td>
        </tr>
        </table>
    </form>
</div>
<?php echo $this->fetch('footer.html'); ?>
